const studentModel = require("../models/studentModel");

module.exports = {
    async ShowAllStudents() {
        return await studentModel.find().populate("class", "name -_id").exec()
    },
    //注册用户
    async AddStudent(username, age, gender, score, address) {
        return await studentModel.create({
            name: username,
            age,
            gender,
            score,
            address
        })
    },
    //删除
    async DelStudentsId(studentId) {
        return await studentModel.deleteOne({
            '_id': studentId
        }).exec()
    },
    //查询学生（_id）
    async getStudentsId(studentId) {
        return await studentModel.findById(studentId).exec()
    },
    //修改学生（_id）
    async updStudentsId({
        '_id': studentId
    }, {
        name,
        age,
        gender,
        score,
        address
    }) {
        return await studentModel.updateOne({
            '_id': studentId
        }, {
            name,
            age,
            gender,
            score,
            address
        }).exec()
    },
}

